package cn.aj.exm.fallback;

import cn.aj.exm.exception.GlobalExceptionEnum;
import cn.aj.exm.feign.MovieService;
import cn.aj.exm.result.JsonResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class MovieServiceFallbackFactory implements FallbackFactory<MovieService> {
    @Override
    public MovieService create(Throwable throwable) {
        return new MovieService() {
            @Override
            public JsonResult list() {
                return JsonResult.error(GlobalExceptionEnum.ERROR.getMessage(), GlobalExceptionEnum.ERROR.getCode());
            }

            @Override
            public JsonResult get(Long id) {
                return JsonResult.error(GlobalExceptionEnum.ERROR.getMessage(), GlobalExceptionEnum.ERROR.getCode());
            }

            @Override
            public JsonResult buyTicket(Long movieId, Integer count) {
                return JsonResult.error(GlobalExceptionEnum.ERROR.getMessage(), GlobalExceptionEnum.ERROR.getCode());
            }

            @Override
            public JsonResult sendMovieTicket(Long movieId, Integer count, Long userId) {
                return JsonResult.error(GlobalExceptionEnum.ERROR.getMessage(), GlobalExceptionEnum.ERROR.getCode());
            }
        };
    }
}
